import pytest
import os


def pytest_addoption(parser):
    parser.addini("base_url", "Base url for api test", default="www.xiaoxue.com")
    parser.addini("max_retry", "最大重试次数", default='3')
    parser.addini("env", "当前测试环境", default='dev')


# 提供配置fixture
@pytest.fixture(scope="session")
def config(pytestconfig):
    return {
        "base_url": pytestconfig.getini("base_url"),
        "max_retry": pytestconfig.getini("max_retry"),
        "env": pytestconfig.getini("env")
    }


# 根据环境跳过测试
@pytest.fixture(autouse=True)
def skip_prod(config, request):
    if config['env'] == "production" and "not_prod" in request.keywords:
        pytest.skip("Skipping test in production environment")
